﻿Public Class Login

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Application.Exit()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Me.TextBox1.Text = "" Then
            MessageBox.Show("Ingrese un USUARIO para loguearse en el Sistema", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error)
            Me.TextBox1.Focus()
        Else
            If Me.TextBox2.Text = "" Then
                MessageBox.Show("Ingrese una CONTRASEÑA para loguearse en el Sistema", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Me.TextBox2.Focus()
            Else
                Try
                    usuario_datarow_global = Me.DbcoverDataSet.Tables(0).Select("username='" & Me.TextBox1.Text & "' and password='" & Me.TextBox2.Text & "'")
                    If usuario_datarow_global.Length = 1 Then
                        If usuario_datarow_global(0)("tipoUsuario") = "ADMINISTRADOR" Then

                        ElseIf usuario_datarow_global(0)("tipoUsuario") = "VENDEDOR" Then
                            My.Forms.Menu.Button_Ingredientes.Enabled = False
                            My.Forms.Menu.Button_Recetas.Enabled = False
                            My.Forms.Menu.Button_Productos.Enabled = False
                            'My.Forms.Menu.Button_Usuarios.Enabled = False
                        ElseIf usuario_datarow_global(0)("tipoUsuario") = "SUPERADMIN" Then

                        End If
                        My.Forms.Menu.ShowDialog()
                    Else
                        MsgBox("No existe el usuario o la contraseña")
                    End If
                Catch ex As Exception
                    MessageBox.Show(ex.ToString)
                End Try
            End If
        End If

    End Sub

    Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: esta línea de código carga datos en la tabla 'DbcoverDataSet.Usuario' Puede moverla o quitarla según sea necesario.
        Me.UsuarioTableAdapter.Fill(Me.DbcoverDataSet.Usuario)

    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            Call Me.Button1_Click("", e)
        End If
    End Sub

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            Me.TextBox2.Focus()
        End If
    End Sub

    Private Sub UsuarioBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.UsuarioBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbcoverDataSet)

    End Sub
End Class
